home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8693 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: gambier.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Handling complex numbers...
  5. Date: 5 Mar 1996 13:40:03 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4hicbjINN91t@gambier.ugrad.cs.ubc.ca>
  8. References: <4hi113$2i8k@mercury.cc.uottawa.ca>
  9. NNTP-Posting-Host: gambier.ugrad.cs.ubc.ca
  10.  
  11. In article <4hi113$2i8k@mercury.cc.uottawa.ca>,
  12. Charles Tran <ctran@csi.uottawa.ca> wrote:
  13. >Dear fellow netters,
  14. >
  15. >Can someone kindly explain to me how to represent complex numbers in C?
  16.  
  17. A structure containing the real and imaginary part can be sufficient.
  18.  
  19. typedef struct {
  20.     double real;
  21.     double imag;
  22. } complex_t;
  23.  
  24. >I am writing a numerical method program to calculate the area under
  25. >a curve using Simpson's Rule.  The problem that I face right now is
  26. >the representation of "i" (where i^2 = -1) in my C program.
  27.  
  28. complex_t i = { 0, 1 };
  29.  
  30. :)
  31.  
  32. >Here's a simple example of what I mean:
  33. >  
  34. >  _b
  35. > |           
  36. > | exp(ix) dx 
  37. >_|             
  38. >a
  39. >
  40. >
  41. >How do I implement this function exp(ix)?
  42.  
  43. Look up the definition in your text on complex analysis. 
  44.  
  45. exp(ix) = cos(x) + i sin(x),  x real
  46.  
  47.  
  48. You might just want to implement exp(z), where z = x + iy, since z = it is just
  49. a special case. Again, just look up the definition!
  50.  
  51. With the general purpose exp(z), you can loop a real number from a to b,
  52. multiply each step value by i, and then subject it to exp(z). As an
  53. optimization, you might want to  have a special function or macro that
  54. multiplies by i, or take it outside the loop altogether.
  55.  
  56. -- 
  57.  
  58.